package com.hy.net.interceptor

import android.util.Log
import com.hy.net.constant.*
import com.hy.net.helper.RetrofitHelper
import com.hy.net.manager.CookiesManager
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @author mingyan.su
 * @date   2023/3/27 07:25
 * @desc   头信息拦截器
 * 添加头信息
 */
class HeaderInterceptor : Interceptor {
    companion object{
        private const val TAG = "HeaderInterceptor"
    }

    override fun intercept(chain: Interceptor.Chain): Response {

        // 如果支持添加头
        if (RetrofitHelper.isAddHeader()) {
            val headers: Map<String, String> = RetrofitHelper.getHeaders()
            if (headers.isNotEmpty()) {
                val builder = chain.request().newBuilder()
                headers.forEach { (key, value) ->
                    builder.addHeader(key, value)
                }
                return chain.proceed(builder.build())
            }
        }
        return chain.proceed(chain.request())
    }
}